from threading import Thread, Lock, current_thread
import time

gNum = 0
mutex = Lock()

def test1():
  print('-----thread name is %s------'%current_thread().name)
  global gNum
  mutex.acquire()  
  for i in range(1000000):
    gNum += 1
  mutex.release()
  print('-------test1--------gNum = %d'%gNum)

def test2():
  print('-----thread name is %s------'%current_thread().name)
  global gNum
  mutex.acquire()
  for i in range(1000000):
    gNum += 1
  mutex.release()
  print('------test2--------gNum =%d'%gNum)


p1 = Thread(target=test1)
p1.start()

#time.sleep(3)

p2 = Thread(target=test2)
p2.start()

